package com.example.zrq1010110087.weight_calculate;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Switch;
import android.widget.TextView;

/**
 * Created by zrq1010110087 on 2017/9/13.
 * Calculate weight by weightResult(PersonUntils person) and show data
 */

public class ResultPage extends AppCompatActivity {

    private TextView sex_tv;
    private TextView height_tv;
    private TextView weight_tv;
    private  TextView name_tv;

    private  PersonUntils person;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.result_activity);
        sex_tv=(TextView) findViewById(R.id.sex_tv);
        height_tv=(TextView) findViewById(R.id.height_tv);
        weight_tv=(TextView) findViewById(R.id.weight_tv);
        name_tv=(TextView) findViewById(R.id.name_tv);
        //获取intent携带的bundle对象,取出数据
       person=(PersonUntils)this.getIntent().getSerializableExtra("person");
        //将用户提交的数据显示
        if(person.getName()!=null)
        name_tv.append(person.getName());
        sex_tv.append(person.getSex());
        height_tv.append(person.getHeight()+"cm");
        //计算weight
        weightResult(person);
        weight_tv.append(person.getWeight()+"kg");





    }
    //计算weight
    private void weightResult(PersonUntils person){

        int weight = 0;

        if(person.getSex().equals("男性")){

            if(person.getHeight()>150)
            weight= person.getHeight()-105;
            else if(person.getHeight()>120)
                weight= person.getHeight()-80;
            else  if(person.getHeight()>90)
                weight= person.getHeight()-70;
            else
                weight= 20;


        }
        if(person.getSex().equals("女性")){

            if(person.getHeight()>150)
                weight= person.getHeight()-110;
            else if(person.getHeight()>120)
                weight=  person.getHeight()-87;
            else  if(person.getHeight()>90)
                weight=  person.getHeight()-73;
            else
                weight= 18;

        }
        person.setWeight(weight);

    }

    public  void return_bt(View v){

        Intent intent=new Intent(this,User_operation.class);
        startActivity(intent);
    }
}
